
static const INVALID_NUM = -7FFFFFFF;
//!@ summary conver string to number 
//!@ param[in]  str_num  number in string format
//!@ return     int of number, or -infinite with error
int amazon_atoi( char* str_num )
{
	if (!str_num) return INVALID_NUM;
	if (!*str_num) return INVALID_NUM;

	char *p = str_num;
	while (*p==' ' || *p=='\t' || *p=='\n' || *p=='\r') p++;

	if( *p <'0' || *p >'9') //Start with invalid char
		return INVALID_NUM;
	
	bool bNeg=false;
	if( *p=='+' || *p=='-'){ bNeg=(*p=='-');p++;}

	int ret=0;
	//while (*p!='\0' && (*p>='0' && *p<='9')){
	try
	{
		while( *p != '\0' )
		{
			if( *p >= '0' && *p <= '9' )
			{
				ret = ret*10 + (*p-'0');
				p++;
			}
			else
			{
				return INVALID_NUM;
			}
		}
	}
	catch( std::overflow_error& )
	{
		return INVALID_NUM;
	}
	return bNeg?-ret:ret;

}